﻿using AutoMapper;
using MediatR;
using MyMES.Domain.W.Liststructure;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using MyMES.Writer.API.Application.Commends.W.realize;

namespace MyMES.Writer.API.Application.CommendHandlers.W.realize
{
    public class DelProductionReportCommandHanders : IRequestHandler<DelProductionReportCommands, APIResult<ProductionReport>>
    {
        private readonly IBaseRepository<ProductionReport> baseRepository;
        private readonly IMapper mapper;

        public DelProductionReportCommandHanders(IBaseRepository<ProductionReport> baseRepository, IMapper mapper)
        {
            this.baseRepository = baseRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 删除生产报工
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<ProductionReport>> Handle(DelProductionReportCommands request, CancellationToken cancellationToken)
        {
            APIResult<ProductionReport> result=new APIResult<ProductionReport> ();
            result.Code = APIEnum.删除成功;
            result.Msg = "删除成功";
            var map = mapper.Map<ProductionReport>(request);
            var list = $"Update ProductionReport set IsDelete=true where ProductionReportId='{request.ProductionReportId}'";
            await baseRepository.Update(map, list);
            return result;
        }
    }
}
